<?php if( $_SERVER['REQUEST_METHOD'] === 'POST' ) : ?>

<?php 
// https://blog.csdn.net/wakice/article/details/58586866
$upload_dir = './files/';
$message = '';
if (!move_uploaded_file($_FILES['up_file']['tmp_name'],$upload_dir.$_FILES['up_file']['name']))
      $message = "文件上传失败，错误信息：".htmlspecialchars($_FILES['up_file']['error']);
else
      $message = "文件 ".htmlspecialchars($_FILES['up_file']['name'])." 上传成功";
// save file; This not work even if i change the upload_tmp_dir in php.ini, 2019-09-01 xbb
//var_dump($_FILES['up_file']);
?>
<script>window.parent.alert('<?php echo $message; ?>');</script>
 
<?php else: ?>
<iframe name="ansynform" style="display:none;" ></iframe>
<form action="upload.php" target="ansynform" method="POST" enctype="multipart/form-data">
<input type="file" name="up_file" />
<input type="submit" value="上传" />
</form>
 
<?php endif; ?>